﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Collections;

namespace WebNhaXuatBan
{
    public partial class GianHangSach : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        [WebMethod]
        public static string LayDanhSachSach(int sobatdau, int maLoai,string text)
        {
            string thanChuoi="";
   BUS.SachBUS sach=new BUS.SachBUS();
   ArrayList dssach= sach.LayDanhSachSachTheoMaLoaiSach(maLoai.ToString());
   int soBatDau = sobatdau;
   int count = dssach.Count;
   int sotrang = 0;
   if (dssach.Count > 5)
   {
       count = 5;
       sotrang = dssach.Count / 5;
       if (dssach.Count % 5 > 0)
       {
           if (soBatDau == dssach.Count / 5)
           {
               count = dssach.Count % 5;
           }
           sotrang++;
       }
   }
   if (sotrang != 0 && sotrang != 1)
   {
       thanChuoi += "<a style=" + (char)34 + " margin-left:2px; color:#4ba2d5;" + (char)34 + " href=" + (char)34 + "#TrangDau" + (char)34 + " onclick=" + (char)34 + "LayDanhSach(0," + maLoai + ",'" + text + "')" + (char)34 + ">Trang Đầu</a>";
     int sob = soBatDau / 10;
                sob = sob * 10;
                int soc = sob + 10;
                if (soc > sotrang)
                {
                    soc = sotrang;
                }
                if (sob != 0)
                {
                    thanChuoi += "<a style=" + (char)34 + " margin-left:5px; color:#4ba2d5;" + (char)34 + " href=" + (char)34 + "#TrangDau" + (char)34 + " onclick=" + (char)34 + "LayDanhSach(" + (sob - 1) + "," + maLoai + ",'" + text + "')" + (char)34 + "><< Trước</a>";
        }
            for (int i = sob; i < soc; i++)
            {
                if (i == soBatDau)
                {
                    thanChuoi+="<span  style=" + (char)34 + " margin-left:5px;"+ (char)34 + ">"+i+"</span>";
                }
                else
                {
                    thanChuoi += "<a style=" + (char)34 + "margin-left:5px; color:#4ba2d5;" + (char)34 + " href=" + (char)34 + "#TrangDau" + (char)34 + " onclick=" + (char)34 + "LayDanhSach(" + i + "," + maLoai + ",'" + text + "')" + (char)34 + ">" + i + "</a>";
                }
            }
            if (soc < sotrang)
            {
                thanChuoi += "<a style=" + (char)34 + "margin-left:5px; color:#4ba2d5;" + (char)34 + " href=" + (char)34 + "#TrangDau" + (char)34 + " onclick=" + (char)34 + "LayDanhSach(" + soc + "," + maLoai + ",'" + text + "')" + (char)34 + ">" + soc + "</a>";
            }
            if (sotrang != 0 && sotrang != 1)
            {
                thanChuoi += "<a style=" + (char)34 + " margin-left:5px; color:#4ba2d5;" + (char)34 + " href=" + (char)34 + "#TrangDau" + (char)34 + " onclick=" + (char)34 + "LayDanhSach(" + (sotrang - 1) + "," + maLoai + ",'" + text + "')" + (char)34 + ">Trang Cuối</a>";
            }
        }
   thanChuoi += "<br /><span style='margin-left:2px;margin-top:5px;'>Hiển Thị: " + count + "/" + dssach.Count + " kết quả</span>";
   for (int j = soBatDau*5; j < soBatDau*5+count; j++)
   {
   thanChuoi+="<hr />";
   thanChuoi+="<div style="+(char)34 +"height:300px;margin-top:5px;margin-left:5px;width:100%;"+(char)34 +">";
   thanChuoi+="<div style="+(char)34 +"height:300px;float:left;width:300px;"+(char)34 +">";
   thanChuoi+="<a href="+(char)34 +"#"+(char)34 +"><img src="+(char)34 +((DTO.SachDTO)dssach[j]).FileHinh+(char)34 +" alt="+(char)34 +((DTO.SachDTO)dssach[j]).FileHinh +(char)34 +") /></a>";
   thanChuoi+="</div>";
   thanChuoi+="<div style="+(char)34 +"height:300px;float:left;width:600px;"+(char)34 +">";
   thanChuoi+="<span style="+(char)34 +"color:#366276; font-size:30px;"+(char)34 +">"+ ((DTO.SachDTO)dssach[j]).TenSach+"</span>";
   thanChuoi+="<br />";
       thanChuoi+="Tác Giả: "+((DTO.SachDTO)dssach[j]).TacGia;
   thanChuoi+="<br />";
   thanChuoi+="<span style="+(char)34 +" color:red;"+(char)34 +" >Giá Bán: "+ ((DTO.SachDTO)dssach[j]).GiaBan +"$</span>";
   thanChuoi+="<br />";
   thanChuoi+="Thể Loại: "+(char)34 +"  "+(char)34 +text;
   thanChuoi+="<br />";
   thanChuoi+="<span style="+(char)34 +"color:red;"+(char)34 +">";
       if (((DTO.SachDTO)dssach[j]).SoLuongTon != 0)
                              { thanChuoi+=" Còn Hàng";}
                              else
                              {thanChuoi+="Hết Hàng";}thanChuoi+="</span>";
   thanChuoi+="<br />";
   thanChuoi+="<a href="+(char)34 +"ThanhToan.aspx?MaSach="+((DTO.SachDTO)dssach[j]).MaSach+(char)34 +"><img src="+(char)34 +"Images/buttonmuahang1.jpg"+(char)34 +" /></a>";
       thanChuoi+="</div>";
    thanChuoi+="</div>";
   }
   thanChuoi += "<div style=" + (char)34 + "width:980px;height:10px;" + (char)34 + "></div>";
            return thanChuoi;
        }
    }
}